package com.edu.exam.entity.curriculum.questionbank;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 论述题参考答案实体类
 * 所属模块：B-02 题库管理模块
 * 对应数据库表：essay_answers
 * 对应数据库表：essay_answer
 * 
 * 管理论述题的参考答案信息，包括标准答案、关键点、评分指南等。
 * 支持答案版本管理、激活/停用状态管理。
 * 关联论述题实体、创建人等信息。
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Comment("论述题参考答案表")
@SQLDelete(sql = "UPDATE essay_answer SET is_deleted = true, delete_time = CURRENT_TIMESTAMP WHERE id = ?")
@Where(clause = "is_deleted = false")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class EssayAnswer {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @NotNull(message = "题目ID不能为空")
    @Column(name = "question_id", nullable = false)
    @Comment("关联题目ID")
    private Long questionId;

    @NotBlank(message = "答案类型不能为空")
    @Size(max = 30, message = "答案类型长度不能超过30个字符")
    @Column(name = "answer_type", nullable = false, length = 30)
    @Comment("答案类型")
    private String answerType;

    @Column(name = "standard_answer", columnDefinition = "TEXT")
    @Comment("标准答案")
    private String standardAnswer;

    @Column(name = "key_points", columnDefinition = "TEXT")
    @Comment("关键点")
    private String keyPoints;

    @Column(name = "scoring_guide", columnDefinition = "TEXT")
    @Comment("评分指南")
    private String scoringGuide;

    @Column(name = "examples", columnDefinition = "TEXT")
    @Comment("示例答案")
    private String examples;

    @Column(name = "common_errors", columnDefinition = "TEXT")
    @Comment("常见错误")
    private String commonErrors;

    @NotNull(message = "版本号不能为空")
    @Column(name = "version", nullable = false)
    @Comment("版本号")
    private Integer version;

    @NotBlank(message = "状态不能为空")
    @Column(name = "status", nullable = false, length = 20)
    @Comment("状态")
    private String status;

    @NotNull(message = "创建人ID不能为空")
    @Column(name = "creator_id", nullable = false)
    @Comment("创建人ID")
    private Long creatorId;

    @NotNull(message = "创建时间不能为空")
    @Column(name = "created_time", nullable = false)
    @Comment("创建时间")
    private LocalDateTime createdTime;

    @NotNull(message = "更新时间不能为空")
    @Column(name = "updated_time", nullable = false)
    @Comment("更新时间")
    private LocalDateTime updatedTime;

    @Column(name = "activate_time")
    @Comment("激活时间")
    private LocalDateTime activateTime;

    @Column(name = "deactivate_time")
    @Comment("停用时间")
    private LocalDateTime deactivateTime;

    @Column(name = "similarity_threshold")
    @Comment("相似度阈值")
    private BigDecimal similarityThreshold;

    @Column(name = "word_count")
    @Comment("答案字数统计")
    private Integer wordCount;

    @Column(name = "readability_score")
    @Comment("可读性分数")
    private BigDecimal readabilityScore;

    @NotNull(message = "删除标志不能为空")
    @Column(name = "is_deleted", nullable = false)
    @Comment("是否删除")
    @Builder.Default
    private Boolean isDeleted = false;

    @Column(name = "delete_time")
    @Comment("删除时间")
    private LocalDateTime deleteTime;

    @Size(max = 500, message = "删除原因长度不能超过500个字符")
    @Column(name = "delete_reason", length = 500)
    @Comment("删除原因")
    private String deleteReason;

    @Column(name = "meta_data", columnDefinition = "TEXT")
    @Comment("扩展元数据(JSON格式)")
    private String metaData;

}
